package com.baizw.cultivation.module.flowable.controller;

import com.baizw.cultivation.common.page.CustomPage;
import com.baizw.cultivation.common.response.ResultBean;
import com.baizw.cultivation.common.response.ResultPage;
import com.baizw.cultivation.module.flowable.entity.ModelEntity;
import com.baizw.cultivation.module.flowable.service.IModelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 模型控制器
 *
 * @author 剧终1204
 * @version V1.0
 * @date 2020年12月01日 15:37
 */
@RestController
@AllArgsConstructor
@Api(tags = "模型控制器")
@RequestMapping("/api/model")
public class ModelController {
	
	private final IModelService modelService;
	
	@PostMapping("/list")
	@ApiOperation("分页查询模型列表")
	public ResultPage<ModelEntity> listPage(@RequestBody CustomPage<ModelEntity> entityPage) {
		CustomPage<ModelEntity> entityCustomPage = modelService.page(entityPage);
		return ResultPage.success(entityCustomPage);
	}
	
	@GetMapping("/detail/{modelId}")
	@ApiOperation("根据模型ID获取模型信息")
	public ResultBean<ModelEntity> getDetailById(@PathVariable String modelId) {
		ModelEntity modelEntity = modelService.getById(modelId);
		return ResultBean.ok(modelEntity);
	}
	
	@DeleteMapping("/delete/{modelId}")
	@ApiOperation("根据模型ID删除模型信息")
	public ResultBean<ModelEntity> removeById(@PathVariable String modelId) {
		ModelEntity modelEntity = modelService.getById(modelId);
		return ResultBean.ok(modelEntity);
	}
	
	@ApiOperation("导入模型")
	@PostMapping("/import")
	public ResultBean<String> importModel(@RequestParam("file") MultipartFile file) {
		boolean importModel = modelService.importModel(file);
		return ResultBean.isTrue(importModel);
	}
}
